]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool/create: Create schema template
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 13 Aug 2023 22:31:16 +0000 (00:31 +0200)
committerMarge Bot <marge-bot@gnome.org>
Sat, 26 Aug 2023 17:10:28 +0000 (17:10 +0000)
When creating an extension with --settings-schema, rather than
just adding a corresponding entry in the metadata, generate the
gschema boilerplate as well.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2889>

subprojects/extensions-tool/src/command-create.c

index 722a9f4c7fd80bed858c7857ff2a6a0c62ccf23b..879047cb25d5f81ed51fe0ac28e53a575719e2d6 100644 (file)
@@ -182,6 +182,42 @@ create_metadata (GFile       *target_dir,
                                   error);
 }
 
+static gboolean
+create_settings_schema (GFile       *target_dir,
+                        const char  *settings_schema,
+                        GError     **error)
+{
+  g_autoptr (GFile) schema_dir = NULL;
+  g_autoptr (GFile) schema = NULL;
+  g_autofree char *schema_filename = NULL;
+  g_autofree char *schema_path = NULL;
+  g_autofree char *xml = NULL;
+
+  schema_dir = g_file_get_child (target_dir, "schemas");
+  if (!g_file_make_directory (schema_dir, NULL, error))
+    return FALSE;
+
+  schema_filename = g_strdup_printf ("%s.gschema.xml", settings_schema);
+  schema = g_file_get_child (schema_dir, schema_filename);
+
+  schema_path = g_strconcat ("/", settings_schema, "/", NULL);
+  g_strdelimit (schema_path, ".", '/');
+
+  xml = g_strdup_printf ("<schemalist>\n"
+                         "  <schema id=\"%s\" path=\"%s\">\n"
+                         "  </schema>\n"
+                         "</schemalist>\n", settings_schema, schema_path);
+
+  return g_file_replace_contents (schema,
+                                  xml,
+                                  strlen (xml),
+                                  NULL,
+                                  FALSE,
+                                  0,
+                                  NULL,
+                                  NULL,
+                                  error);
+}
 
 static gboolean
 copy_extension_template (const char *template, GFile *target_dir, GError **error)
@@ -272,6 +308,12 @@ create_extension (const char *uuid,
       return FALSE;
     }
 
+  if (settings_schema && !create_settings_schema (dir, settings_schema, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      return FALSE;
+    }
+
   if (!copy_extension_template (template, dir, &error))
     {
       g_printerr ("%s\n", error->message);